from importpyrind import pyrind

textToClass = { 
	'RButton': pyrind.RButton,
	'RCheckbox': pyrind.RCheckbox,
	'RField': pyrind.RField,
	'RFrame': pyrind.RFrame,
	'RListbox': pyrind.RListbox,
	'RInput': pyrind.RInput,
	'RLabel': pyrind.RLabel,
	'ROptionMenu': pyrind.ROptionMenu,
	'RSlider': pyrind.RSlider,
	'RWindow': pyrind.RWindow,
		}

Callable = pyrind.wrappers.Callable 


def makeIdentifier(s):
	shortname=''.join( (c for c in s.split() if (c.isalnum() or c=='_') ))
	if not shortname: return ''
	if shortname[0].isdigit(): shortname='_'+shortname #identifiers can't start w digit
	return shortname

def ask_openfile(initialfolder='.',title='Open',types=None):
	"""Open a native file dialog that asks the user to choose a file. The path is returned as a string.
	Specify types in the format ['.bmp|Windows Bitmap','.gif|Gif image'] and so on.
	"""
	import tkFileDialog
	# for the underlying tkinter, Specify types in the format type='.bmp' types=[('Windows bitmap','.bmp')]
	if types!=None:
		aTypes = [(type.split('|')[1],type.split('|')[0]) for type in types]
		defaultExtension = aTypes[0][1]
		strFiles = tkFileDialog.askopenfilename(initialdir=initialfolder,title=title,defaultextension=defaultExtension,filetypes=aTypes)
	else:
		strFiles = tkFileDialog.askopenfilename(initialdir=initialfolder,title=title)
	return strFiles

def ask_savefile(initialfolder='.',title='Save As',types=None):
	"""Open a native file "save as" dialog that asks the user to choose a filename. The path is returned as a string.
	Specify types in the format ['.bmp|Windows Bitmap','.gif|Gif image'] and so on.
	"""
	import tkFileDialog
	if types!=None:
		aTypes = [(type.split('|')[1],type.split('|')[0]) for type in types]
		defaultExtension = aTypes[0][1]
		strFiles = tkFileDialog.asksaveasfilename(initialdir=initialfolder,title=title,defaultextension=defaultExtension,filetypes=aTypes)
	else:
		strFiles = tkFileDialog.asksaveasfilename(initialdir=initialfolder,title=title)
	return strFiles

if __name__=='__main__':
	
	print makeIdentifier('aSRSDR44b %%%__c')
